package com.aspose.cells.b.a.b.d.a;

import com.aspose.cells.a.d.zfq;
import com.aspose.cells.a.d.zfs;
import com.aspose.cells.b.a.zf;
import com.aspose.cells.b.a.zu;
import com.aspose.cells.b.a.b.zg;
import com.aspose.cells.b.a.b.zh;
import com.aspose.cells.b.a.b.zv;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.font.TextAttribute;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;

public class zd implements Cloneable {
   private final float a;
   private final float b;
   private final zv c;
   private final String d;
   private final zg e;
   private final float f;
   private static String g = null;
   private static final AffineTransform h = AffineTransform.getRotateInstance(1.5707963267948966D);
   private za i;
   private int j;
   private int k;
   private int l;
   private float m;
   private int n = 0;
   private Graphics2D o;
   private FontMetrics p;
   private zfq q;

   public zd(String var1, zg var2, zv var3, float var4, float var5, Graphics2D var6) {
      this.c = var3 != null ? var3 : new zv();
      this.e = var2;
      this.d = var1 != null ? var1 : "";
      zh var7 = var2.b();
      if (this.c.e()) {
         this.f = 0.0F;
      } else {
         this.f = var2.h() * (float)var7.a(var2.k()) / (float)var7.e(var2.k());
      }

      this.a = var4;
      this.b = var5;
      if (var6 == null) {
         BufferedImage var8 = new BufferedImage(1, 1, 1);
         var6 = (Graphics2D)var8.getGraphics();
      }

      if (var6 != null) {
         this.p = var6.getFontMetrics(this.e.a());
      }

      try {
         this.q = zfs.b(this.e.g(), this.e.k(), false);
      } catch (Exception var9) {
         ;
      }

      this.o = var6;
   }

   public Graphics2D a() {
      return this.o;
   }

   public FontMetrics b() {
      return this.p;
   }

   public zfq c() {
      return this.q;
   }

   public final float d() {
      return !this.c.f() ? this.f() : this.e();
   }

   public final float e() {
      return this.a;
   }

   public final float f() {
      return this.b;
   }

   public final zv g() {
      return this.c;
   }

   public final float h() {
      return this.f;
   }

   public final int i() {
      return this.j;
   }

   public final float j() {
      return this.m;
   }

   public float k() {
      return this.e.h();
   }

   public final AffineTransform l() {
      return !this.g().f() ? new AffineTransform() : h;
   }

   public float a(float var1) {
      return this.c.e() ? var1 : var1 * 1.028F + 0.463F * this.k();
   }

   public float b(float var1) {
      return this.c.e() ? var1 : 1.08864F * var1;
   }

   public zc m() {
      if (this.k < this.l && !this.c.i()) {
         return this.o();
      } else {
         this.j += this.l;
         if (this.j >= this.d.length()) {
            return null;
         } else {
            int var2 = this.d.indexOf(g, this.j);
            String var1;
            if (var2 >= 0) {
               var1 = this.d.substring(this.j, this.j + var2 - this.j + g.length());
            } else {
               var1 = this.d.substring(this.j);
            }

            this.l = var1.length();
            this.k = 0;
            AttributedString var3 = new AttributedString(var1);
            var3.addAttribute(TextAttribute.FONT, this.e.a());
            if ((this.e.k() & 4) != 0) {
               var3.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
            }

            if ((this.e.k() & 8) != 0) {
               var3.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
            }

            AttributedCharacterIterator var4 = var3.getIterator();
            this.i = new za(var1, this.q, this.e);
            return this.o();
         }
      }
   }

   public AffineTransform n() {
      if (this.c.b() == 0) {
         return null;
      } else {
         float var1 = this.d();
         if (zu.b(var1)) {
            var1 = 0.0F;
         }

         float var2 = var1 - this.j();
         if (var1 > 0.0F && var2 <= 0.0F) {
            return null;
         } else {
            if (this.c.b() == 1) {
               var2 /= 2.0F;
            } else if (this.c.f() && this.c.g()) {
               return null;
            }

            return this.c.f() ? AffineTransform.getTranslateInstance((double)var2, 0.0D) : AffineTransform.getTranslateInstance(0.0D, (double)var2);
         }
      }
   }

   private final zc o() {
      if (this.m >= this.d()) {
         this.j += this.k;
         return null;
      } else {
         int var1 = this.i.a(this.p, this.k, this.e());
         if (var1 <= 0) {
            return null;
         } else {
            int var2 = var1;
            if (var1 < this.l) {
               while(var2 >= this.k && !com.aspose.cells.b.a.zd.a(this.d, this.j + var2)) {
                  --var2;
               }

               if (var2 > this.k) {
                  var1 = var2 + 1;
               }
            }

            if (var1 <= this.k) {
               return null;
            } else {
               String var3 = this.i.a(this.k, var1);
               zc var4 = new zc(this, this.m, var3, this.e);
               ++this.n;
               float var5 = var4.d() + var4.e();
               if (this.n == 1) {
                  var5 += var4.f();
               }

               var5 = this.b(var5);
               if (this.c != null && this.c.h() && this.m + var5 > this.b) {
                  return null;
               } else {
                  this.m += var5;

                  for(this.k = var1; this.k < this.l && com.aspose.cells.b.a.zd.a(this.d, this.j + this.k); ++this.k) {
                     ;
                  }

                  return var4;
               }
            }
         }
      }
   }

   static {
      g = zf.a();
      if (g == null || g.length() == 0 || g.charAt(g.length() - 1) == '\n') {
         g = "\n";
      }

   }
}
